
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.Timer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Riso-Desktop
 */
public class Strela extends JComponent implements Runnable {
    int x;
    int y;
    JFrame f;
    int smer;
    Thread t = new Thread(this);
    boolean naraz = false;
    public Strela(JFrame j,int x, int y, int smer){
        this.x= x;
        this.y= y;
        this.smer=smer;
        this.f = j;
        setBounds(x, y, 5, 5);
        t.start();
    }

    @Override
    public void paint(Graphics g) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, 5, 5);
    }
    @Override
    public void run() {
        while(!naraz){
            try {
                t.sleep(30);
            } catch (Exception e) {
            }
        if(smer==1){
            this.setLocation(getX()+3, getY());
            if(naraz){
            f.remove(this);
            }
        }
        if(smer==2){
            this.setLocation(getX()-3, getY());
            if(naraz){
            f.remove(this);
            }
        }
        if(smer==3){
            this.setLocation(getX(), getY()+3);
            if(naraz){
            f.remove(this);
            }
        }
        if(smer==4){
            this.setLocation(getX(), getY()-3);
            if(naraz){
            f.remove(this);
            }
        }
            
        }
    }
}
